package main

import (
	"log"

	"fmt"

	"github.com/name5566/leaf/db/mongodb"
	"gopkg.in/mgo.v2/bson"
)

const (
	url          = "mongodb://admin:123456@192.168.1.61:27017/admin"
	testDB       = "test"
	testTable    = "test"
	counterTable = "counter"
	accountTable = "account"
)

func nextSequence(db *mongodb.DialContext, id string) (int, error) {
	return db.NextSeq(testDB, counterTable, id)
}

func main() {
	db, err := mongodb.Dial(url, 1)
	if err != nil {
		panic(err)
	}
	defer db.Close()

	err = db.EnsureUniqueIndex(testDB, testTable, []string{"name", "key"})
	if err != nil {
		log.Panicf("ensure index error: %v", err)
	}
	err = db.EnsureCounter(testDB, counterTable, accountTable)
	if err != nil {
		log.Panicf("ensure counter error: %v", err)
	}

	fmt.Println(bson.NewObjectId().Hex())
}
